﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class art_rate_type : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.DateTime? _date;
private System.Int32? _rate_type_id;
private System.Int32? _art_id;
private System.Int32? _user_id;
private art _art;
private rate_type _rate_type;
private user _user;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

/// <summary>
/// This property contains a calculated, bindable value of the DATE part of a DateTime property. If you want to only work with the DATE and ignore the underlying TIME component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String date_Date 
{
get
{
if (  !date.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( date.Value.ToShortDateString() == System.DateTime.MinValue.ToShortDateString() ) 
 return String.Empty;
else  
 return date.Value.ToShortDateString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(date_Time)) {

date = null;
}
 else
{
 date = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + date.Value.ToString("HH:mm:ss.fff") ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(date_Time)) 
{
 date = Convert.ToDateTime( " " + value + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
 else
{
 date = Convert.ToDateTime( " " + value + " " + date.Value.ToString("HH:mm:ss.fff") ) ;
}
}

}
}

/// <summary>
/// This property contains a calculated, bindable value of the TIME part of a DateTime property. If you want to only work with the TIME and ignore the underlying DATE component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String date_Time 
{
get
{
if (  !date.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( date.Value.ToShortTimeString() == System.DateTime.MinValue.ToShortTimeString() ) 
 return String.Empty;
else  
 return date.Value.ToShortTimeString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(date_Date)) 
{
date = null;
}
 else
{
 date = Convert.ToDateTime( " " + date.Value.ToShortDateString() + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(date_Date)) 
{
 date = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + value ) ;
}
 else
{
 date = Convert.ToDateTime( " " + date_Date + " " + value ) ;
}
}

}
}

public virtual System.DateTime? date 
{
get
{
return _date;
}
set 
{
if ( _date != value) 
{
_date = value ;
OnPropertyChanged("date");
}
}
}

public virtual System.Int32? rate_type_id 
{
get
{
if ( rate_type != null ) 
{
_rate_type_id = (System.Int32)rate_type.id;
}

return _rate_type_id;
}
set 
{
if ( _rate_type_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_rate_type = null;

_rate_type_id = value ;
OnPropertyChanged("rate_type_id");
}
}
}

public virtual System.Int32? art_id 
{
get
{
if ( art != null ) 
{
_art_id = (System.Int32)art.id;
}

return _art_id;
}
set 
{
if ( _art_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_art = null;

_art_id = value ;
OnPropertyChanged("art_id");
}
}
}

public virtual System.Int32? user_id 
{
get
{
if ( user != null ) 
{
_user_id = (System.Int32)user.id;
}

return _user_id;
}
set 
{
if ( _user_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_user = null;

_user_id = value ;
OnPropertyChanged("user_id");
}
}
}

/// <summary>
/// Generated from Relation FK_Art_Rate_type_Art
/// </summary>
[GenWiseAttribute(RelationID = "91dd5bf9-ce4c-4fd6-bedb-c220b9b80686") ]
public virtual art art 
{
get
{
if ( _art == null ) 
{
if ( !_art_id.HasValue || _art_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _art != null && ( _art.id.Equals(null) ) )
{
  _art = null;
}
}
else
{
_art = (new artFactory()).Get(_art_id.Value);
}
}

return _art;
}
set 
{
if ( _art != value) 
{
if ( value==null ) _art_id = null; else _art_id = (System.Int32)value.id; 
_art = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Art_Rate_type_Rate_type
/// </summary>
[GenWiseAttribute(RelationID = "eba7c57a-c6e5-49a6-b18c-7d7a8a8f9f04") ]
public virtual rate_type rate_type 
{
get
{
if ( _rate_type == null ) 
{
if ( !_rate_type_id.HasValue || _rate_type_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _rate_type != null && ( _rate_type.id.Equals(null) ) )
{
  _rate_type = null;
}
}
else
{
_rate_type = (new rate_typeFactory()).Get(_rate_type_id.Value);
}
}

return _rate_type;
}
set 
{
if ( _rate_type != value) 
{
if ( value==null ) _rate_type_id = null; else _rate_type_id = (System.Int32)value.id; 
_rate_type = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Art_Rate_type_User
/// </summary>
[GenWiseAttribute(RelationID = "19b7cb74-63b7-4b0d-86d9-777c9652f016") ]
public virtual user user 
{
get
{
if ( _user == null ) 
{
if ( !_user_id.HasValue || _user_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _user != null && ( _user.id.Equals(null) ) )
{
  _user = null;
}
}
else
{
_user = (new userFactory()).Get(_user_id.Value);
}
}

return _user;
}
set 
{
if ( _user != value) 
{
if ( value==null ) _user_id = null; else _user_id = (System.Int32)value.id; 
_user = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new art_rate_type object. 
/// </summary>
public  art_rate_type()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

